import axios from 'axios';

const request = axios.create({
  timeout: 10000
});

// 请求拦截器
request.interceptors.request.use(config => {
  const token = localStorage.getItem('token');
  if (token) {
    config.headers.auth = `${token}`;
  }
  return config;
}, error => {
  return Promise.reject(error);
});

// 响应拦截器
request.interceptors.response.use(response => {

  return response;
}, error => {
  if (error.response.status === 401) {
    // 未登录，跳转登录页面
    window.location.href = '/login';
  }

  return Promise.reject(error);
});


export default request; 